﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.BLL
{
    public class StockInBill
    {
        #region 封装属性

        private string mStockInNum;   //入库单号

        public string StockInNum
        {
            get { return mStockInNum; }
            set { mStockInNum = value; }
        }

        private StockInType mStockInTypeNum;  //入库方式

        public StockInType StockInTypeNum
        {
            get { return mStockInTypeNum; }
            set { mStockInTypeNum = value; }
        }

        private DateTime mStockInDatetime; //入库日期

        public DateTime StockInDatetime
        {
            get { return mStockInDatetime; }
            set { mStockInDatetime = value; }
        }

        private Supplier mSupplierNum;   //供货单位代号

        public Supplier SupplierNum
        {
            get { return mSupplierNum; }
            set { mSupplierNum = value; }
        }

        private Drug mDrugNum;

        public Drug DrugNum
        {
            get { return mDrugNum; }
            set { mDrugNum = value; }
        }

        private DateTime mProductedDatetime; //生产日期

        public DateTime ProductedDatetime
        {
            get { return mProductedDatetime; }
            set { mProductedDatetime = value; }
        }

        private DateTime mExpiryDatetime; //有效日期

        public DateTime ExpiryDatetime
        {
            get { return mExpiryDatetime; }
            set { mExpiryDatetime = value; }
        }

        private float mTradePrice; //批发价

        public float TradePrice
        {
            get { return mTradePrice; }
            set { mTradePrice = value; }
        }

        private float mRetailPrice; //零售价

        public float RetailPrice
        {
            get { return mRetailPrice; }
            set { mRetailPrice = value; }
        }

        private float mImportPrice;   //进货价

        public float ImportPrice
        {
            get { return mImportPrice; }
            set { mImportPrice = value; }
        }

        private string mBatchNum;   //批号

        public string BatchNum
        {
            get { return mBatchNum; }
            set { mBatchNum = value; }
        }

        private int mQuantity; //入库数量

        public int Quantity
        {
            get { return mQuantity; }
            set { mQuantity = value; }
        }

        private float mAmount;  //金额

        public float Amount
        {
            get { return mAmount; }
            set { mAmount = value; }
        }

        private string mCreatedBy;   //制单人

        public string CreatedBy
        {
            get { return mCreatedBy; }
            set { mCreatedBy = value; }
        }

        private DateTime mCreatedDatetime;  //制单时间

        public DateTime CreatedDatetime
        {
            get { return mCreatedDatetime; }
            set { mCreatedDatetime = value; }
        }

        private string mApprovalBy;  //审核人

        public string ApprovalBy
        {
            get { return mApprovalBy; }
            set { mApprovalBy = value; }
        }

        private DateTime mApprovalDatetime;  //审核时间

        public DateTime ApprovalDatetime
        {
            get { return mApprovalDatetime; }
            set { mApprovalDatetime = value; }
        }

        private string mRemark;  //备注

        public string Remark
        {
            get { return mRemark; }
            set { mRemark = value; }
        }

        private string mStatus;  //状态
           
        public string Status
        {
            get { return mStatus; }
            set { mStatus = value; }
        }

        #endregion

        private IStockInBillDAL stockInBillDAL;

        public StockInBill()
        {
            stockInBillDAL = Adapter.GetStockInBill();

        }

        public void FetchObject(IDataReader dr)
        {
            if (dr != null)
            {
                mStockInNum = ConvertDataType.CheckFiledString(dr["stock_in_num"]);
                mStockInTypeNum.StockInTypeNum = ConvertDataType.CheckFiledInt(dr["stock_in_type_num"]);
                mSupplierNum.SupplierNum = ConvertDataType.CheckFiledInt(dr["supplier_num"]);
                mStockInDatetime = ConvertDataType.CheckFiledDateTime(dr["stock_in_datetime"]);
                mRemark = ConvertDataType.CheckFiledString(dr["remark"]);
                mStatus = ConvertDataType.CheckFiledString(dr["status"]);
                mTradePrice = ConvertDataType.CheckFieldFloat(dr["trade_price"]);
                mRetailPrice = ConvertDataType.CheckFieldFloat(dr["retail_price"]);
                mImportPrice = ConvertDataType.CheckFieldFloat(dr["import_price"]);
                mQuantity = ConvertDataType.CheckFiledInt(dr["quantity"]);
                mProductedDatetime = ConvertDataType.CheckFiledDateTime(dr["producted_datetime"]);
                mAmount = ConvertDataType.CheckFiledInt(dr["amount"]);
                mApprovalBy = ConvertDataType.CheckFiledString(dr["approval_by"]);
                mApprovalDatetime = ConvertDataType.CheckFiledDateTime(dr["approval_datetime"]);
                mBatchNum = ConvertDataType.CheckFiledString(dr["batch_num"]);
                mCreatedBy = ConvertDataType.CheckFiledString(dr["created_by"]);
                mCreatedDatetime = ConvertDataType.CheckFiledDateTime(dr["created_datetime"]);
                mDrugNum.DrugCode = ConvertDataType.CheckFiledString(dr["drug_num"]);
                mExpiryDatetime = ConvertDataType.CheckFiledDateTime(dr["expiry_datetime"]);
            }
        }

        public bool CreateStockInBill(StockInBill stockInBill)
        {
            return stockInBillDAL.Insert(stockInBill.StockInNum, stockInBill.StockInTypeNum.StockInTypeNum, stockInBill.StockInDatetime, stockInBill.SupplierNum.SupplierNum, stockInBill.DrugNum.DrugNum, stockInBill.ProductedDatetime, stockInBill.ExpiryDatetime, stockInBill.TradePrice, stockInBill.RetailPrice, stockInBill.ImportPrice, stockInBill.BatchNum, stockInBill.Quantity, stockInBill.Amount, stockInBill.CreatedBy, stockInBill.ApprovalBy, stockInBill.ApprovalDatetime, stockInBill.Remark, stockInBill.Status) > 0 ? true : false;
        }

        //public   DataTable GetStockInDisplay(int PageIndex,int PageSize,string StockInTypeName,string StockInNum)
        //{
        //    StockInBillDAL store = new StockInBillDAL();
        //    return store.Select(PageIndex, PageSize, StockInTypeName, StockInNum);
        //}

        public  DataTable Display()
        {
            return stockInBillDAL.Select();
        }

        public  DataTable DisplayHeaderByStatus(string Status)
        {
            return stockInBillDAL.Select(Status);
        }

        public  bool RemoveStockInBill(string stockInNum)
        {
            return stockInBillDAL.Delete(stockInNum) > 0 ? true : false;
        }
    }
}
